package adapter;

import java.util.concurrent.*;

/**
 * @ClassName RunnableAdapter
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/6/30 11:29
 * @Versio 1.0
 */
public class RunnableAdapter<T> implements Runnable {

	private Callable<T> callable;

	public RunnableAdapter(Callable callable) {
		this.callable = callable;
	}
	@Override
	public void run() {
		try {
			final T call = callable.call();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

class MyRunnable implements Runnable {

	DataDemo result;

	public MyRunnable(DataDemo result) {
		this.result = result;
	}
	@Override
	public void run() {
		System.out.println("set result");
		result.setResult("成功.");
	}
}

class DataDemo{
	private String result;

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
}


class Test{
	public static void main(String[] args) throws ExecutionException, InterruptedException {
//		Runnable runnable=()->{
//			System.out.println("runnable");
//		};
//
//		Runnable runnable1=new Runnable() {
//			String result;
//			@Override
//			public void run() {
//
//			}
//		};
//
		Callable<Long> callable = () -> {
			System.out.println("call able used");
			return 1L * 2;
		};

		final RunnableAdapter<Long> adapter = new RunnableAdapter<Long>(callable);
		final Thread thread = new Thread(adapter);
		thread.start();
		thread.join();
//		final Thread t1 = new Thread(runnable);
//		final Thread t2 = new Thread(callable);

		final ExecutorService executorService = Executors.newFixedThreadPool(3);
//		final Future<?> submit = executorService.submit(runnable);
//		final Future<Long> submit1 = executorService.submit(callable);
		DataDemo dataDemo = new DataDemo();
		final MyRunnable myRunnable = new MyRunnable(dataDemo);

		final Future<DataDemo> submit = executorService.submit(myRunnable, dataDemo);

//		System.out.println(submit.get());
//		System.out.println(submit1.get());
		System.out.println(submit.get().getResult());
		executorService.shutdown();
	}


}
